﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Storage;

namespace ShaderLab
{
    // Wishlist
    //texturing
    //specular texturing
    //multitexturing
    public class Material
    {

        #region Material Properties
        Color diffuseColor;
        public Color DiffuseColor
        {
            get { return diffuseColor; }
            set { 
                diffuseColor = value;
                structDiffuseColor.SetValue(diffuseColor.ToVector3());
            }
        }

        Color emissiveColor;
        public Color EmissiveColor 
        {
            get { return emissiveColor; }
            set { 
                emissiveColor = value;
                structEmissiveColor.SetValue(emissiveColor.ToVector3());
            }
        }

        Color specularColor;
        public Color SpecularColor
        {
            get { return specularColor; }
            set { 
                specularColor = value;
                structSpecularColor.SetValue(specularColor.ToVector3());
            }
        }

        float specularPower;
        public float SpecularPower
        {
            get { return specularPower; }
            set {
                specularPower = value;
                structSpecularPower.SetValue(specularPower);
            }
        }

        float alpha;
        public float Alpha
        {
            get { return alpha; }
            set {
                alpha = value;
                structAlpha.SetValue(alpha);
            }
        }
        #endregion


        #region Effect
        Effect effect;
        public Effect Effect
        {
            get { return effect; }
        }

        EffectParameter structInstance, structDiffuseColor, structAlpha, structEmissiveColor, structSpecularColor, structSpecularPower;
        #endregion


        #region Initialization
        public Material(GraphicsDevice graphics, Effect baseEffect)
        {
            effect = baseEffect.Clone(graphics);

            structInstance = effect.Parameters["Material"];
            structDiffuseColor = structInstance.StructureMembers["DiffuseColor"];
            structAlpha = structInstance.StructureMembers["Alpha"];
            structEmissiveColor = structInstance.StructureMembers["EmissiveColor"];
            structSpecularColor = structInstance.StructureMembers["SpecularColor"];
            structSpecularPower = structInstance.StructureMembers["SpecularPower"];

            DiffuseColor = Color.White;
            EmissiveColor = Color.Black;
            SpecularColor = Color.White;
            SpecularPower = 16f;
            Alpha = 1f;
        }
        #endregion

    }
}
